<?php
use yii\helpers\Html;
use backend\models\Group;

/* @var $this \yii\web\View */
/* @var $content string */
?>
<link rel="stylesheet" type="text/css" href="/css/bootstrap.css">
<script src="/js/jquery.js" type="text/javascript"></script>
<script src="/js/nav.js" type="text/javascript"></script>
<header class="main-header">
<?php
    $channel = Yii::$app->redis->get('channel_all_'.Yii::$app->user->getIdentity()->id);
    $channel = explode(',', $channel);
?>
<!--    --><?//= Html::a('<span class="logo-mini">APP</span><span class="logo-lg">' . Yii::$app->name . '</span>', Yii::$app->homeUrl, ['class' => 'logo']) ?>
    <span class="logo">
    <select id="channel" class="selectpicker"  style="width: 200px;height: 40px;border: hidden;border-radius: 1px;background-color: #0f74a8;box-shadow: 0 0 5px #ccc;position: relative;font-size:large">
            <?php foreach($channel as $v):?>
        <option value="<?= $v;?>" <?php if($v == Yii::$app->redis->get('channel_'.Yii::$app->user->getIdentity()->id)):?>selected<?php endif;?>>
            <?php if($v == 'admin'):?>管理后台<?php elseif($v == 'yunying'):?>运营后台<?php elseif($v == 'config'):?>配置后台<?php else:?>官网后台<?php endif;?>
        </option>
            <?php endforeach;?>
        </select>
    </span>


    <nav class="navbar navbar-static-top" role="navigation">

        <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
            <span class="sr-only">Toggle navigation</span>
        </a>

        <div class="navbar-custom-menu">

            <ul class="nav navbar-nav">

                <!-- Messages: style can be found in dropdown.less-->
                
                <!-- Tasks: style can be found in dropdown.less -->
                
                <!-- User Account: style can be found in dropdown.less -->

                <li class="dropdown user user-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <img src="<?= $directoryAsset ?>/img/user2-160x160.jpg" class="user-image" alt="User Image"/>
                        <span class="hidden-xs"><?= Yii::$app->user->getIdentity()->username;?></span>
                    </a>
                    <ul class="dropdown-menu">
                        <!-- User image -->
                        <li class="user-header">
                            <img src="<?= $directoryAsset ?>/img/user2-160x160.jpg" class="img-circle"
                                 alt="User Image"/>
                        </li>
                        <!-- Menu Footer-->
                        <li class="user-footer">
                            <div class="pull-left">
                                <a href="/user/alter-password" class="btn btn-default btn-flat">修改密码</a>
                            </div>
                            <div class="pull-right">
                                <?= Html::a(
                                    'Sign out',
                                    ['/login/logout'],
                                    ['data-method' => 'post', 'class' => 'btn btn-default btn-flat']
                                ) ?>
                            </div>
                        </li>
                    </ul>
                </li>

                <!-- User Account: style can be found in dropdown.less -->
                <li>
                    <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
                </li>
            </ul>
        </div>
    </nav>
</header>
<script>
    $('#channel').change(function()
    {
        $.ajax({
            url: "/user/channel",
            type: "post",
            dataType: "json",
            data: {'channel': $(this).val()},
            success: function (data) {
                window.location.href = "/";
            }
        })
    })
    </script>